<template>
  <div @click="backClick" class="go-back">
    <div class="left">
      <van-icon size="5.6vw" name="arrow-left" />
    </div>
    <div class="center">
      <slot name="center"></slot>
    </div>
    <div class="right">
      <slot name="right"></slot>
    </div>
  </div>
</template>

<script lang="js">
import {defineComponent, reactive, ref} from 'vue'
import { useRouter } from 'vue-router'

export default defineComponent({
  props: {
   routerPath:{
     type:String,
     default:''
   }
  },
  components: {

  },
  setup(props) {
    const path=ref(props.routerPath)

    const router = useRouter();
     const backClick=()=>{
      //  如果不传 routerPath参数 默认跳转前一个路由
       if(path.value.length>0){
          router.push(path.value)
       }else{
          router.go(-1)
       }

     }

    return {
      backClick
    }

  }
})
</script>

<style scoped lang="less">
.go-back {
  display: flex;
  align-items: center;
  color: var(--van-white-color);
  background-color: var(--van-theme-color);
  font-weight: 550;
  .left,
  .right {
    width: 60px;
  }
  .center {
    flex: 1;
    text-align: center;
  }
}
</style>
